﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using T.ApiResults;
using T.Contract.API.Application.Command.ContractCommand;
using T.Contract.API.Application.Command.TrackingCommand;

namespace T.Contract.API.Controllers
{
    /// <summary>
    /// API控制器--跟踪
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TrackingController : ControllerBase
    {
        /// <summary>
        /// 
        /// </summary>
        protected readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">Mediator</param>
        public TrackingController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 修改货主合同跟踪状态
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddContract(UpdateTrackingCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
